var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
import React, { useCallback, useRef } from "react";
import PickerPanel from "../components/picker-panel";
import Picker from "../components/picker-view";
import useOverlay from "./useOverlay";
import { useCountyDataContext } from "../uses/useCoutryDataContext";
var useCityPicker = function () {
    var countyData = useCountyDataContext().countyData;
    var overlay = useOverlay();
    var pickerValueRef = useRef([]);
    var show = useCallback(function (props) {
        return overlay.show(function () {
            return (React.createElement(PickerPanel, __assign({}, props, { title: props.title, onCancel: function () {
                    overlay.close();
                    pickerValueRef.current = null;
                }, onConfirm: function () {
                    overlay.close();
                    props.onConfirm && props.onConfirm(pickerValueRef.current);
                    pickerValueRef.current = null;
                } }),
                React.createElement(Picker, __assign({}, props, { linkage: true, dataSource: countyData, onChange: function (value) {
                        var _a;
                        pickerValueRef.current = __spread(value);
                        (_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value);
                    } }))));
        }, {
            type: 'slid-up'
        });
    }, [countyData]);
    return __assign(__assign({}, overlay), { show: show });
};
export default useCityPicker;
